package com.haierp.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.haierp.model.KpiWarehouse;
import com.haierp.service.IKpiWarehouseService;
import com.wangzhixuan.commons.base.BaseController;

/**
 *
 * KpiWarehouse 控制层
 *
 */
@Controller
@RequestMapping("/kpi")
public class KpiController extends BaseController{

	@Autowired
	private IKpiWarehouseService kpiWarehouseService;

	@RequestMapping("/queryKpiWarehouse")
	public String queryKpiWarehouse(HttpServletRequest request) {
		List<KpiWarehouse> kpiWarehouseList = kpiWarehouseService.selectKpiWarehouseByMonth();
		Map<String, KpiWarehouse> shipMap = new HashMap<String,KpiWarehouse>();
		kpiWarehouseList.forEach(kpiWarehouse -> {
			if(shipMap.containsKey(kpiWarehouse.getDimensionDate())) {
				KpiWarehouse kpiWarehouseTemp = shipMap.get(kpiWarehouse.getDimensionDate());
				kpiWarehouseTemp.setCount(kpiWarehouseTemp.getCount()+1);
			} else {
				KpiWarehouse kpiWarehouseTemp = new KpiWarehouse();
				kpiWarehouseTemp.setCount(1);
				shipMap.put(kpiWarehouse.getDimensionDate(), kpiWarehouseTemp);
			}
		});
		request.setAttribute("shipMap", shipMap);
		request.setAttribute("kpiWarehouseList", kpiWarehouseList);
		return "kpi/kpiWarehouse";
	}
}